package cate.game.activity.config;

import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "活动开启配置",detail = "记录在玩家身上")
public class ActivityBaseCfgPO {

	@NoteField(value = "活动ID",detail = "配置在活动基础表中的id 用于区分不同期的活动 充值项中的subFuncId需要与这个id一致")
	public int activityId;

	@NoteField("功能ID")
	public int funcId;

	@NoteField("配置ID")
	public int configTid;

	@NoteField(value = "开始时间")
	public long startTime;

	@NoteField(value = "结束时间")
	public long endTime;


	/**
	 * 活动配置是否变更
	 * 	应对循环活动，时间完全不重合的活动也按照不是同一期活动处理
	 */
	public boolean eq(ActivityBaseCfg cfg) {
		return funcId == cfg.funcId
				&& activityId == cfg.activityId
				&& configTid == cfg.configTid
				&& startTime < cfg.endTime
				&& endTime > cfg.startTime;
	}

	/**
	 * 活动配置是否变更
	 * 	应对循环活动，时间完全不重合的活动也按照不是同一期活动处理
	 */
	public boolean eq(ActivityBaseCfgPO cfg) {
		return funcId == cfg.funcId
				&& activityId == cfg.activityId
				&& configTid == cfg.configTid
				&& startTime < cfg.endTime
				&& endTime > cfg.startTime;
	}

	public void clear(){
		this.activityId = 0;
		this.funcId = 0;
		this.configTid = 0;
		this.startTime = 0;
		this.endTime = 0;
	}

	public void read(ActivityBaseCfg cfg){
		this.activityId = cfg.activityId;
		this.funcId = cfg.funcId;
		this.configTid = cfg.configTid;
		this.startTime = cfg.startTime;
		this.endTime = cfg.endTime;
	}

	public void readTime(ActivityBaseCfg cfg){
		this.startTime = cfg.startTime;
		this.endTime = cfg.endTime;
	}

	public boolean readTime(ActivityBaseCfgPO cfgPO) {
		boolean changed = false;
		if (this.startTime != cfgPO.startTime) {
			this.startTime = cfgPO.startTime;
			changed = true;
		}
		if (this.endTime != cfgPO.endTime) {
			this.endTime = cfgPO.endTime;
			changed = true;
		}
		return changed;
	}

	public static ActivityBaseCfgPO EMPTY(int funcId) {
		ActivityBaseCfgPO cfg = new ActivityBaseCfgPO();
		cfg.funcId = funcId;
		return cfg;
	}

	public ActivityBaseCfgPO copy() {
		ActivityBaseCfgPO po = new ActivityBaseCfgPO();
		po.activityId = this.activityId;
		po.funcId = this.funcId;
		po.configTid = this.configTid;
		po.startTime = this.startTime;
		po.endTime = this.endTime;
		return po;
	}

	public boolean active() {
		return activityId > 0;
	}
}
